package cmd

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/spf13/cobra"
)

// diffCmd represents the diff command
var syncCmd = &cobra.Command{
	Use: "sync",
	Run: func(cmd *cobra.Command, args []string) {
		client := http.Client{}
		req, err := http.NewRequest("GET", cmd_url_prefix+"/api/sync", nil)
		if err != nil {
			fmt.Printf("创建请求失败: %v\n", err)
			return
		}
		// q := req.URL.Query()
		// file, _ := cmd.Flags().GetString("file")
		// q.Add("file", file)
		// req.URL.RawQuery = q.Encode()
		resp, err := client.Do(req)
		if err != nil {
			fmt.Printf("请求失败: %v\n", err)
			return
		}
		defer resp.Body.Close()
		buf, _ := ioutil.ReadAll(resp.Body)
		fmt.Print(string(buf))
	},
}

func init() {
	rootCmd.AddCommand(syncCmd)

	// useCmd.Flags().String("file", "", "service file")
	// useCmd.MarkFlagRequired("file")
}
